Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #159: Adds dict support for DefaultFilter #386

Merged
merged 5 commits into from
Jan 17, 2020

Conversation

gabru-md
Copy link
Contributor

adds a fix for #159

prev discussion : #344

@gabru-md gabru-md changed the title Fixes #159: Adds dict support for DefaulFilter Fixes #159: Adds dict support for DefaultFilter Jan 15, 2020
Copy link
Contributor

@jboulter jboulter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good to me with a few minor changes.

String... args) {
Object... args) {

List<String> stringArgs = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do this all in one loop. In fact, you don't need stringArgs at all. I know this was just moved from another file, but might as well clean it up while we're in here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done 👍

if (arg.length < 1) {
throw new TemplateSyntaxException(interpreter, getName(), "requires 1 number (divisor) argument");
}
String toMul = arg[0];
String toMul = arg[0] == null ? null : Objects.toString(arg[0]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Objects.toString takes care of nulls for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs state that it returns "null" and not null.
Also if I use Objects.toString(arg[0]) then the following test breaks. Therefore had to ensure that arg[0] == null check was made.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good to know.

@@ -61,7 +64,7 @@ public Object filter(Object object, JinjavaInterpreter interpreter, String... ar
return object;
}

return args[0];
return (args[0] instanceof PyWrapper) ? args[0] : Objects.toString(args[0]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the only real significant change, right?

Copy link
Contributor Author

@gabru-md gabru-md Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. basically checking if the argument is an instance of PyWrapper then we do not need to convert it into String.

@boulter boulter requested a review from mattcoley January 16, 2020 19:23
Copy link
Collaborator

@mattcoley mattcoley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants